package leetcode.easy;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: $22_GenerateParenthesis
 * Description:
 * date: 2022-02-18 21:24
 *
 * @author liyifan
 */
public class $22_GenerateParenthesis {

    List<String> res = new ArrayList<>();

    public List<String> generateParenthesis(int n) {
        dfs(n, 0, 0, "");
        return res;
    }

    public void dfs(int n, int l, int r, String path){
        if (path.length() >= 2 * n){res.add(path); return;}

        if (l < n) {
            dfs(n, l + 1, r, path + "(");
        }

        if (r < n && r < l) {
            dfs(n, l, r, path + ")");
        }
    }
}
